<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2023-12-13 14:28:22
 * @LastEditors: wiz
 * @LastEditTime: 2024-07-11 18:29:55
-->
<template>
  <o-modal
    v-model="isShow"
    :title="config.modalTitle"
    :size="config.modalSize"
    :mask="true"
    :tap-close="false"
    :show-footer="true"
    @on-ok="confirm"
    @on-close="cancel"
  >
    <div slot="content" class="urgentbox clear">
      <Form :label-width="80">
        <FormItem :label="$srv.getI18nByValue('用户名')">
          <Input
            v-model="messageData.toUserNo"
            :placeholder="$srv.getI18nByValue('请输入用户编号')"
          ></Input>
        </FormItem>
        <FormItem :label="$srv.getI18nByValue('设备ID')">
          <Input
            disabled
            v-model="messageData.toClientID"
            :placeholder="$srv.getI18nByValue('请输入客户端ID')"
          ></Input>
        </FormItem>
        <FormItem :label="$srv.getI18nByValue('通信类型')">
          <Select v-model="messageData.msg.cmd">
            <Option :value="0">{{ $srv.getI18nByValue('消息') }}</Option>
            <Option :value="1" disabled>{{
              $srv.getI18nByValue('数据采集类')
            }}</Option>
            <Option :value="2" disabled>{{
              $srv.getI18nByValue('会谈')
            }}</Option>
          </Select>
        </FormItem>
        <FormItem :label="$srv.getI18nByValue('消息类型')">
          <Select v-model="messageData.msg.m.t">
            <Option :value="0">{{ $srv.getI18nByValue('广播') }}</Option>
            <Option :value="1" disabled>{{
              $srv.getI18nByValue('预警')
            }}</Option>
            <Option :value="2" disabled>{{
              $srv.getI18nByValue('警报')
            }}</Option>
            <Option :value="3">{{ $srv.getI18nByValue('通知') }}</Option>
            <Option :value="4">{{ $srv.getI18nByValue('待办事项') }}</Option>
          </Select>
        </FormItem>
        <FormItem :label="$srv.getI18nByValue('消息体')">
          <div>
            <Select
              v-model="messageData.msg.m.d.msgType"
              style="margin-bottom: 10px;"
            >
              <Option :value="0">{{ $srv.getI18nByValue('第一级') }}</Option>
              <Option :value="1" disabled>{{
                $srv.getI18nByValue('第二级')
              }}</Option>
              <Option :value="2" disabled>{{
                $srv.getI18nByValue('第三级')
              }}</Option>
            </Select>
            <Input
              v-model="messageData.msg.m.d.msgContent.msgTitle"
              :placeholder="$srv.getI18nByValue('请输入消息标题')"
            ></Input>
          </div>
        </FormItem>
      </Form>
    </div>
  </o-modal>
</template>

<script lang="ts">
import oModal from '@/components/base/modal/o-modal/index.vue';
import { Component, Prop, Vue } from 'vue-property-decorator';
import { T_wsMsg, Tsrv } from './command';

interface config {
  modalTitle?: string;
  modalSize?: Array<number>;
}

@Component({
  components: {
    oModal
  }
})
export default class oSendMessage extends Vue {
  @Prop() config: config;

  @Prop() id: string;

  private isShow: boolean = false;

  private messageData: T_wsMsg = new T_wsMsg();

  created() {}

  mounted() {
    this.show();
  }

  // public sendMessage() {
  //   const msg = new T_wsMsg();
  //   // msg.setToUserNo('dev03'); // "__ALLUSERS__"
  //   // msg.setToClientID(null);
  //   // msg.setCMD(0); // 0：消息、数据采集类、会谈
  //   // msg.setMsgType(0); // 0：广播、预警、警报、通知、待办事项、更新token
  //   // msg.setData('{"userNo":"dev03", "userPass":"123456", "dbName":"test"}');

  //   const msgBody = new T_msgContent();
  //   msgBody.setMsgType(0); // 消息类型细分--"单据审核"
  //   msgBody.setMsgContent({
  //     msgTitle: '测试消息标题',
  //     funName: 'stan_doc',
  //     billNo: '443319534632304640'
  //   });
  //   msg
  //     .setToUserNo('dev03')
  //     .setToClientID(null)
  //     .setCMD(0)
  //     .setMsgType(4)
  //     .setData(msgBody);
  //   Tsrv.sendMsg(msg);
  // }

  public show() {
    this.isShow = true;
  }

  public hide() {
    this.$bus.$emit(`modal_${this.id}`);
    this.isShow = false;
  }

  public confirm() {
    Tsrv.sendMsg(this.messageData);
    this.$bus.$emit(`modal_${this.id}`, '消息返回');
    this.hide();
  }

  public cancel() {
    this.hide();
  }
}
</script>

<style lang="scss" scoped>
.urgentbox {
  padding: 0 20px;
  height: 100%;
  overflow-y: scroll;
}
</style>
